<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:jsf="http://xmlns.jcp.org/jsf"
      xmlns:ui="http://java.sun.com/jsf/facelets">

    <f:metadata>
                <f:viewParam name="event" value="#{editEventBean.eventId}"/>
                <f:event type="preRenderView" listener="#{editEventBean.editEventInit}" />
    </f:metadata>

    <h:head>
        <title>Edit Event</title>
    </h:head>
    <h:body>
        <ui:composition template="headerTemplate.xhtml">
            <ui:define name="content">

                <h:form id="eventForm" class="form-horizontal">

                    <h2>Edit Event</h2>

                    <div class="col-md-6">
                        <!-- Text input-->
                        <div class="form-group">
                            <label class="control-label col-md-2" for="title">Title</label>
                            <div class="input-group col-md-10">
                                <div class="col-md-6">
                                    <p:inputText  id="title" value="#{editEventBean.event.title}" placeholder="Insert a title" styleClass="form-control">
                                        <p:ajax update="titlemsg"/>
                                    </p:inputText>
                                </div>
                                <div class="col-md-6">
                                    <p:message id="titlemsg" for="title"/>
                                </div>
                            </div>
                        </div>

                        <!-- Text input-->
                        <div class="form-group">
                            <label class="control-label col-md-2" for="description">Description</label>
                            <div class="input-group col-md-10">
                                <div class="col-md-6">
                                    <p:inputText id="description"  value="#{editEventBean.event.description}" placeholder="Insert a description" class="form-control">
                                        <p:ajax update="descriptionmsg"/>
                                    </p:inputText>
                                </div>
                                <div class="col-md-6">
                                    <p:message id="descriptionmsg" for="description"/>
                                </div>
                            </div>
                        </div>

                        <!-- Text input-->
                        <div class="form-group">
                            <label class="control-label col-md-2" for="city">City</label>
                            <div class="input-group col-md-10">
                                <div class="col-md-6">
                                    <p:inputText id="city" value="#{editEventBean.event.city}" placeholder="Insert a city name" class="form-control">
                                        <p:ajax update="citymsg"/>
                                    </p:inputText>
                                </div>
                                <div class="col-md-6">
                                    <p:message id="citymsg" for="city"/>
                                </div>
                            </div>
                        </div>

                        <!-- Text input-->
                        <div class="form-group">
                            <label class="control-label col-md-2" for="address">Address</label>
                            <div class="input-group col-md-10">
                                <div class="col-md-6">
                                    <p:inputText id="address" value="#{editEventBean.event.addressWithoutCity}" placeholder="Insert an address" class="form-control">
                                        <p:ajax update="addressmsg"/>
                                    </p:inputText>
                                </div>
                                <div class="col-md-6">
                                    <p:message id="addressmsg" for="address"/>
                                </div>
                            </div>
                        </div>

                        <!-- Multiple Radios -->
                        <div class="form-group">
                            <label class="control-label col-md-2">Event privacy</label>
                            <div class=" col-md-10">
                                <p:selectOneRadio id="privacyRadioButton" value="#{editEventBean.event.isPublic}">
                                    <f:selectItem itemLabel="Public" itemValue="#{true}" />
                                    <f:selectItem itemLabel="Private" itemValue="#{false}" />
                                </p:selectOneRadio>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="control-label col-md-2" for="title">Starting time</label>
                            <div class="input-group col-md-10">
                                <div class="col-md-6">
                                    <p:calendar id="startingtime" value="#{editEventBean.startingTime}" pattern="HH:mm a" timeOnly="true">
                                        <p:ajax event="dateSelect" update="startingtimemsg"/>
                                    </p:calendar>
                                </div>
                                <div class="col-md-6">
                                    <p:message id="startingtimemsg" for="startingtime"/>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="control-label col-md-2" for="title">Ending Time</label>
                            <div class="input-group col-md-10">
                                <div class="col-md-6">
                                    <p:calendar id="endingtime" value="#{editEventBean.endingTime}" pattern="HH:mm a" timeOnly="true">
                                        <p:ajax event="dateSelect" update="endingtimemsg"/>
                                    </p:calendar>
                                </div>
                                <div class="col-md-6">
                                    <p:message id="endingtimemsg" for="endingtime"/>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="control-label col-md-2" for="title">Starting Date</label>
                            <div class="input-group col-md-10">
                                <div class="col-md-6">
                                    <p:calendar id="startingdate" value="#{editEventBean.startingDate}" showOn="button">
                                        <p:ajax event="dateSelect" update="startingdatemsg"/>
                                    </p:calendar>
                                </div>
                                <div class="col-md-6">
                                    <p:message id="startingdatemsg" for="startingdate"/>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="control-label col-md-2" for="title">Ending Date</label>
                            <div class="input-group col-md-10">
                                <div class="col-md-6">
                                    <p:calendar id="endingdate" value="#{editEventBean.endingDate}" showOn="button">
                                        <p:ajax event="dateSelect" update="endingdatemsg"/>
                                    </p:calendar>
                                </div>
                                <div class="col-md-6">
                                    <p:message id="endingdatemsg" for="endingdate"/>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">

                        <!-- Search input-->
                        <div class="form-group">

                            <div class="col-md-12">
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <h3 class="panel-title">Users to invite</h3>
                                    </div>
                                    <div class="panel-body">
                                        <ui:repeat id="invitedUsers" value="#{editEventBean.invitedUserListToNotify}" var="user">
                                            #{user.username} <br/>
                                        </ui:repeat>
                                    </div>
                                </div>
                            </div>

                                <div class="col-md-12">
                                    <div class="panel panel-default">
                                        <div class="panel-heading">
                                            <h3 class="panel-title">already invited users</h3>
                                        </div>
                                        <div class="panel-body">
                                            <ui:repeat id="alreadyInvitedUsers" value="#{editEventBean.alreadyInvitedUserList}" var="user">
                                                #{user.username} <br/>
                                            </ui:repeat>
                                        </div>
                                    </div>
                                </div>

                            <div class="col-md-12">
                                <label class="control-label col-md-3" for="searchuser">Search user to invite</label>
                                <div class="input-group col-md-9">
                                    <p:inputText type="text" id="searchuser" value="#{editEventBean.usernameToSearch}" class="form-control" placeholder="Insert a username">
                                        <p:ajax update="searchusermsg"/>
                                    </p:inputText>
                                    <span class="input-group-btn">
                                        <button class="btn btn-default" jsf:update="searchuser,invitedUsers" jsf:action="#{editEventBean.addInsertedUser}">Add</button>
                                    </span>
                                </div><!-- /input-group -->
                                <div class="col-md-6 col-md-offset-3">
                                    <p:message id="searchusermsg" for="searchuser"/>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-12">
                        <button class="pull-right btn btn-success modify-button" jsf:update="eventForm" jsf:action="#{editEventBean.modify()}">Modify</button>
                        <button class="pull-right btn btn-danger" jsf:update="eventForm" jsf:action="#{editEventBean.delete}">Delete</button>
                    </div>

                </h:form>
                
            </ui:define>
        </ui:composition>


    </h:body>
</html>

